from collections import Counter
"""
    383. 赎金信
    给你两个字符串：ransomNote 和 magazine ，判断 ransomNote 能不能由 magazine 里面的字符构成。
    如果可以，返回 true ；否则返回 false 。
"""

class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        d = Counter(magazine)
        for i in ransomNote:
            if i not in d.keys() or d[i] == 0:
                return False
            d[i] -= 1
        return True